1 /*
2  * This file is part of gtkD.
3  *
4  * gtkD is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU Lesser General Public License
6  * as published by the Free Software Foundation; either version 3
7  * of the License, or (at your option) any later version, with
8  * some exceptions, please read the COPYING file.
9  *
10  * gtkD is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public License
16  * along with gtkD; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA
18  */
19 
20 // generated automatically - do not change
21 // find conversion definition on APILookup.txt
22 // implement new conversion functionalities on the wrap.utils pakage
23 
24 
25 module sourceview.IndenterT;
26 
27 public  import gobject.ObjectG;
28 public  import gtk.TextIter;
29 public  import sourceview.View;
30 public  import sourceview.c.functions;
31 public  import sourceview.c.types;
32 
33 
34 /**
35  * Auto-indentation interface.
36  * 
37  * By default, [class@View] can auto-indent as you type when
38  * [property@View:auto-indent] is enabled. The indentation simply copies the
39  * previous lines indentation.
40  * 
41  * This can be changed by implementing `GtkSourceIndenter` and setting the
42  * [property@View:indenter] property.
43  * 
44  * Implementors of this interface should implement both
45  * [vfunc@Indenter.is_trigger] and [vfunc@Indenter.indent].
46  * 
47  * [vfunc@Indenter.is_trigger] is called upon key-press to
48  * determine of the key press should trigger an indentation.  The default
49  * implementation of the interface checks to see if the key was
50  * [const@Gdk.KEY_Return] or [const@Gdk.KEY_KP_Enter] without %GDK_SHIFT_MASK set.
51  * 
52  * [vfunc@Indenter.indent] is called after text has been
53  * inserted into [class@Buffer] when
54  * [vfunc@Indenter.is_trigger] returned %TRUE. The [struct@Gtk.TextIter]
55  * is placed directly after the inserted character or characters.
56  * 
57  * It may be beneficial to move the insertion mark using
58  * [method@Gtk.TextBuffer.select_range] depending on how the indenter changes
59  * the indentation.
60  * 
61  * All changes are encapsulated within a single user action so that the
62  * user may undo them using standard undo/redo accelerators.
63  */
64 public template IndenterT(TStruct)
65 {
66 	/** Get the main Gtk struct */
67 	public GtkSourceIndenter* getIndenterStruct(bool transferOwnership = false)
68 	{
69 		if (transferOwnership)
70 			ownedRef = false;
71 		return cast(GtkSourceIndenter*)getStruct();
72 	}
73 
74 
75 	/**
76 	 * This function should be implemented to alter the indentation of text
77 	 * within the view.
78 	 *
79 	 * @view is provided so that the indenter may retrieve settings such as indentation and tab widths.
80 	 *
81 	 * @iter is the location where the indentation was requested. This typically
82 	 * is after having just inserted a newline (\n) character but can be other
83 	 * situations such as a manually requested indentation or reformatting.
84 	 *
85 	 * See [iface@Indenter.is_trigger] for how to trigger indentation on
86 	 * various characters inserted into the buffer.
87 	 *
88 	 * The implementor of this function is expected to keep @iter valid across
89 	 * calls to the function and should contain the location of the insert mark
90 	 * after calling this function.
91 	 *
92 	 * The default implementation for this virtual function will copy the
93 	 * indentation of the previous line.
94 	 *
95 	 * Params:
96 	 *     view = a #GtkSourceView
97 	 *     iter = the location of the indentation request
98 	 */
99 	public void indent(View view, ref TextIter iter)
100 	{
101 		gtk_source_indenter_indent(getIndenterStruct(), (view is null) ? null : view.getViewStruct(), (iter is null) ? null : iter.getTextIterStruct(true));
102 	}
103 
104 	/**
105 	 * This function is used to determine if a key pressed should cause the
106 	 * indenter to automatically indent.
107 	 *
108 	 * The default implementation of this virtual method will check to see
109 	 * if @keyval is [const@Gdk.KEY_Return] or [const@Gdk.KEY_KP_Enter] and @state does
110 	 * not have %GDK_SHIFT_MASK set. This is to allow the user to avoid
111 	 * indentation when Shift+Return is pressed. Other indenters may want
112 	 * to copy this behavior to provide a consistent experience to users.
113 	 *
114 	 * Params:
115 	 *     view = a #GtkSourceView
116 	 *     location = the location where @ch is to be inserted
117 	 *     state = modifier state for the insertion
118 	 *     keyval = the keyval pressed such as [const@Gdk.KEY_Return]
119 	 *
120 	 * Returns: %TRUE if indentation should be automatically triggered;
121 	 *     otherwise %FALSE and no indentation will be performed.
122 	 */
123 	public bool isTrigger(View view, TextIter location, GdkModifierType state, uint keyval)
124 	{
125 		return gtk_source_indenter_is_trigger(getIndenterStruct(), (view is null) ? null : view.getViewStruct(), (location is null) ? null : location.getTextIterStruct(), state, keyval) != 0;
126 	}
127 }